package fr.norsys.mapper.console.model;

import java.util.Collection;
import java.util.TreeSet;
import fr.norsys.mapper.console.utils.UIDGenerator;

public class Application extends BaseObject {
	private static final long serialVersionUID = 9185138710684496385L;
	private String id;
	private String name;
	private Connection connection = new Connection();
	private String connectionName;
	private Collection resources = new TreeSet(new ResourceNameComparator());
	private Collection variables = new TreeSet(new VariableNameComparator());
	
	public Application() {
		super();
	}
	public Application(String name) {
		super();
		this.id = UIDGenerator.generateId();
		this.name = name;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public Connection getConnection() {
		return connection;
	}
	public void setConnection(Connection connection) {
		this.connection = connection;
	}
	public Collection getResources() {
		return resources;
	}
	public void setResources(Collection resources) {
		this.resources = resources;
	}
	public Collection getVariables() {
		return variables;
	}
	public void setVariables(Collection variables) {
		this.variables = variables;
	}
	public void addResource(Resource resource) {
		if(resource!=null && !"".equals(resource.getId())) {
			resources.add(resource);
		}
	}
	public void deleteResource(Resource resource) {
		if(resource!=null && !"".equals(resource.getId())) {
			resources.remove(resource.getId());
		}
	}
	public void addVariable(Variable variable) {
		if(variable!=null && !"".equals(variable.getId())) {
			variables.add(variable);
		}
	}
	public void deleteVariable(Variable variable) {
		if(variable!=null && !"".equals(variable.getId())) {
			variables.remove(variable);
		}
	}
	public String getConnectionName() {
		return connectionName;
	}
	public void setConnectionName(String connectionName) {
		this.connectionName = connectionName;
	}
	public void clear() {
		connection = new Connection();
		connectionName = "";
		resources.clear();
		variables.clear();
	}
}